package com.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.entity.FileType;
import com.util.DBHelp;
import com.util.RowMapper;

public class FileTypeDao {

	DBHelp<FileType> help=new DBHelp<FileType>();
	
	public List<FileType> getByPid(String id) {
		String sql="SELECT `id`,`name`,`createtime`,`t_employee_id`,`t_project_id` FROM `t_filetype` WHERE `t_project_id`=? ORDER BY `createtime` desc";
		return help.executeQueryForList(sql, new Mapper(), id);
	}
	
	public void add(FileType fileType) {
		String sql="INSERT INTO `t_filetype`(`id`,`name`,`createtime`,`t_employee_id`,`t_project_id`) VALUES(?,?,?,?,?)";
		help.executeSQL(sql, fileType.getId(),fileType.getName(),fileType.getCreatetime(),fileType.getEmployeeid(),fileType.getProjectid());
	}
	
	public FileType getById(String id) {
		String sql="SELECT `id`,`name`,`createtime`,`t_employee_id`,`t_project_id` FROM `t_filetype` WHERE id=?";
		return help.executeQueryForObject(sql, new Mapper(), id);
	}
	
	public void deleteById(String id) {
		String sql="DELETE FROM `t_filetype` WHERE id=?";
		help.executeSQL(sql, id);
	}
	
	private class Mapper implements RowMapper<FileType>{

		public FileType mapperRow(ResultSet rs) throws SQLException {
			FileType fileType=new FileType();
			fileType.setCreatetime(rs.getString("createtime"));
			fileType.setEmployeeid(rs.getString("t_employee_id"));
			fileType.setId(rs.getString("id"));
			fileType.setName(rs.getString("name"));
			fileType.setProjectid(rs.getString("t_project_id"));
			
			return fileType;
		}
		
	}


}
